package com.midnight.rstar.domain;

/**
 * 结果的封装
 *
 * @Author hanbo
 * @Since 2020-03-09
 */
public class NetResult<T> {
    public static final int SUCC = 1;
    public static final int INNER_ERROR = 2;
    public static final int PARAMS_ERROR = 3;

    public static final int CALLER_ERROR = 5004;
    public static final int LOGIN_STATE_LOST = 5000;


    public T data;
    public int code;
    public String msg;


    protected NetResult(T data, int code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }


    public static <T> NetResult<T> succ(T data) {
        return new NetResult<T>(data, SUCC, null);
    }

    public static <T> NetResult<T> succ(T data, String msg) {
        return new NetResult<T>(data, SUCC, msg);
    }

    private NetResult<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }


    public static <T> NetResult<T> fail(int status, String msg) {
        return new NetResult<T>(null, status, msg);
    }

}

